#include "Player.h"

namespace qtangram {
    Player::Player(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f), name("cheater") {
	setupUi(this);
	connect(okButton,SIGNAL(clicked()),this,SLOT(onOkClicked()));
    }
    void Player::onOkClicked() {
	if(playerName->text().isEmpty()) {
	    QMessageBox::critical(this,"Input data error", "Player name cannot be empty.");
	}
	else {
	    name = playerName->text();
	    hide();
	    emit playerNameEntered(name);
	}
    }
    void Player::closeEvent(QCloseEvent*) {
	QMessageBox::information(this, "Notification", "You did not enter player name, despite you were asked for it. If you have "
				 "entered player name earlier, it will remain the same. Otherwise you will be signed as 'cheater', "
				 "however you can change it by clicking Game -> Start new game as a different player.");
	hide();
	playerName->setText(name);
	emit playerNameEntered(name);
    }
}
